package com.preskool.controller;

import com.preskool.dto.ActionResult;
import com.preskool.dto.ExamVo;
import com.preskool.po.Exam;
import com.preskool.service.ExamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * TODO
 *
 * @author ZhaoBo
 * @description:
 * @date 2021/1/7  20:16
 */
@RestController
@Api(value = "考试清单的接口文档")
public class ExamController {
    @Autowired
    private ExamService examService;

    /**
     * 查询全部考试清单
     * @return
     */
    @ApiOperation(value = "Exam:exams",httpMethod = "GET",notes = "查询全部考试清单")
    @RequestMapping(value = "/exams",method = RequestMethod.GET)
    public ActionResult findExamAll(Integer currentPage,Integer pageSize,Integer routeName){
        List<ExamVo> exams = examService.findExams(currentPage,pageSize,routeName);
        if (exams != null){
            return new ActionResult(200,"find successful",exams);
        }
        return new ActionResult(203,"failed",null);
    }

    /**
     *  添加一条考试清单数据
     * @param exam
     * @return
     */
    /*@ApiOperation(value = "Exam:insertExam",httpMethod = "PUT",notes = "添加一条考试清单数据")
    @RequestMapping(value = "/insertExam",method = RequestMethod.PUT)
    public ActionResult insertOne(@RequestBody Exam exam){
        int i = examService.insertExam(exam);
        if (i >0){
            return new ActionResult(200,"insert successful",null);
        }
        return new ActionResult(203,"insert failed",null);
    }*/

    /**
     * 删除一条考试清单
     * @param id
     * @return
     */
    @ApiOperation(value = "Exam:deleteExamOne",httpMethod = "DELETE",notes = "删除一条考试清单")
    @RequestMapping(value = "/deleteExamOne",method = RequestMethod.DELETE)
    public ActionResult deleteExamOne(int id){
        int i = examService.delExam(id);
        if (i >0){
            return new ActionResult(200,"delete successful",null);
        }
        return new ActionResult(203,"delete failed",null);
    }

    /**
     * 修改一条考试清单
     * @param id
     * @return
     */
    @ApiOperation(value = "Exam:updateExam",httpMethod = "POST",notes = "修改一条考试清单")
    @RequestMapping(value = "/updateExam",method = RequestMethod.POST)
    public ActionResult updateExam(@RequestBody Exam exam){
        int i = examService.updateExam(exam);
        if (i >0){
            return new ActionResult(200,"update successful",null);
        }
        return new ActionResult(203,"update failed",null);
    }
}
